﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace rmeloni.Models
{
    public class ProjectRepository
    {
        rmelonidbEntities RM_db_Conn = new rmelonidbEntities();

        public Projetos SelectById(long ident)
        {
            var result = from p in RM_db_Conn.ProjetosSet
                         where p.Id == ident
                         orderby p.Id
                         select p;

            if (result.Count() > 0)
            {
                return result.First();
            }

            return null;
        }

        public IQueryable<Projetos> SelectAll()
        {
            var result = from p in RM_db_Conn.ProjetosSet
                         orderby p.Id
                         select p;

            return result;
        }

        public void Add(Projetos prj)
        {
            RM_db_Conn.AddToProjetosSet(prj);
        }


        public void Delete(Projetos prj)
        {
            RM_db_Conn.DeleteObject(prj);
        }


        public void Save()
        {
            RM_db_Conn.SaveChanges();
        }
    }

}